import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import { viteCommonjs } from '@originjs/vite-plugin-commonjs'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(), 
    viteCommonjs(),
  ],
  server: {
    //https: true,
    proxy:{
        '/biliapi':{
            target:'https://live-open.biliapi.com',
            changeOrigin:true,
            rewrite:path => {
                //console.log( path.replace(/^\/biliapi/, ''))
                return path.replace(/^\/biliapi/, '')
            },
            headers: {
                referer: "https://live-open.biliapi.com",
                origin: "https://live-open.biliapi.com"
            }
        },  
        '/biliws':{
            target:'ws://live-open.biliapi.com/sub',
            changeOrigin:true,
            rewrite:path => {
                //console.log( path.replace(/^\/biliws/, ''))
                return path.replace(/^\/biliws/, '')
            }
        },  
        '/testapi':{
            target:'http://localhost:8080',
            changeOrigin:true,
            rewrite:path => {
                //console.log( path.replace(/^\/biliapi/, ''))
                return path.replace(/^\/testapi/, '')
            }
        },  
    }
  },
  // 配置路径别名
  resolve: {
    alias: {
        "@": resolve(__dirname, "src")
    }
  }
})
